###################################
# Distribution plots
# compare distributions 
# (norm, logit, ALDs)
###################################

# clear memory
rm(list=ls())

# source function
source("distribution/source.R")


t0 <- Sys.time()
# simulate
x=-1000:1000/100
pdf("figures/figure1_2.pdf",width=7,height=7)
plot(NULL,xlim=c(-10,10),ylim=c(0,1),
     xlab = "Values",
     ylab = "Cumulative density",
     main="Cumulative densities")
abline(h=0.5,lwd=0.7,col="gray",lty="dotted")
for (i in seq(0.01,0.99,length.out = 90)){
  lines(x,pald(x,i),lty="solid",
        col = paste("gray",floor(abs(i-0.5)*100),sep="") )  
  if (i > 0.9){
    text(-9.5,pald(-10,i),round(i,2))  
  }
  if (i < 0.1){
    text(9.5,pald(10,i),round(i,2))  
  }
}
# standard normal cdf
lines(x,pnorm(x),lty="solid",lwd=2,col="green")
# logistic with location 0 scale 1
lines(x,plogis(x),lty="solid",lwd=2,col="blue")
text(-9.5,1,expression(paste(tau,"=")))
text(-3,0.8,"Normal",col="green")
text(4,0.8,"Logistic",col="blue")
dev.off()

# performance of tails
x1=0:1000/200
x2=-1000:0/200
pdf("figures/figure1_1.pdf",width = 7,height=7)
plot(NULL,xlim=c(-5,5),ylim=c(0,0.4),
     xlab = "Values",
     ylab = "Density",
     main = "Probability densities")
for (i in seq(0.01,0.5,length.out = 20)){
  lines(x1,dald(x1,i),lty="solid",
        col = paste("gray",floor(abs(i-0.5)*100),sep="") )  
  if (i < 0.3){
    text(0.3,dald(0.2,i),round(i,2))  
  }
}
for (i in seq(0.01,0.5,length.out = 20)){
  lines(x2,dald(x2,i),lty="solid",
        col = paste("gray",floor(abs(i-0.5)*100),sep="") )  
  if (i > 0.7){
    text(-0.3,dald(-0.2,i),round(i,2))  
  }
}
lines(c(x2,x1),dnorm(c(x2,x1) ),col="green")
lines(c(x2,x1),dlogis(c(x2,x1)),col="blue")
text(1.5,0.3,"Normal",col="green")
text(2,0.15,"Logistic",col="blue")
text(-3,0.3,expression(paste(tau %in% "(0.01,0.5)")))
dev.off()

t1 <- Sys.time()

source("distribution/empiricalDistribution_plot.R")

t2 <- Sys.time()

source("distribution/simulation_study.R")

t3 <- Sys.time()



dur1 = t1 - t0
dur2 = t2 - t1
dur3 = t3 - t2
dur4 = t3 - t0
dur1
dur2
dur3
dur4

